package com.xiaoyao.myframeapp.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

/**
 * @Author xiaoyao
 * @Email xiao80206040@qq.com
 * @Explain
 * @Created by Administrator on 2017/6/24 0024 16:14
 */
public class getApp {
    /**
     * get App versionName
     *
     * @param context
     * @return
     */
    //TODO 获取当前版本编号
    public static String getAppVersionName(Context context) {
        String versionName = "";
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionName = packageInfo.versionName;
            if (TextUtils.isEmpty(versionName)) {
                return "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return versionName;
    }

    /**
     * get App versionCode
     *
     * @param context
     * @return
     */
    //TODO 获取当前版本
    public static String getAppVersionCode(Context context) {
        String versionCode = "";
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionCode = packageInfo.versionCode + "";
            if (TextUtils.isEmpty(versionCode)) {
                return "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    //TODO 获取当前手机信息
    public static String getHandSetInfo(Context context) {
        String handSetInfo =
                "手机型号:" + android.os.Build.MODEL +
                        ",SDK版本:" + android.os.Build.VERSION.SDK +
                        ",系统版本:" + android.os.Build.VERSION.RELEASE +
                        ",软件版本:" + getAppVersionName(context);
        return handSetInfo;

    }


}
